<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				userCacheKey:"fin-xz-salaryDeduction-title2-userId-cache"
			})
		},
		methods:{
			getParentUser(id){
				let _that = this
				_that.om.request(
					"salaryDeduction/getParentUser",
					{
						postId: id
					}
				).then(res=>{
					_that.$refs.autoform.formdata.parentUserId = res.value.id
					_that.$refs.autoform.formdata.parentUserName = res.value.username
				})
			},
			getYearMonth(){
				let _that = this
				_that.om.request(
					"salaryDeduction/getYearMonth",
					{
						data:""
					}
				).then(res=>{
					if(res.value){
						_that.$refs.autoform.changeEditor("title2","yearMonth","data",configSelectData(res.value.initDataList,'value','text'))
						if(res.value.initData && !_that.$refs.autoform.formdata.yearMonth){
							_that.$refs.autoform.formdata.yearMonth = res.value.initData
						}
						_that.$refs.autoform.initSelectIndex("title2","yearMonth")
					}
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.userCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.userName = d.username
							formdata.userId = d.id
							formdata.salaryPosId = d.salaryPosId
							formdata.instId = d.salaryPosInstId
							formdata.parentInstId = d.parentInstId
							formdata.salaryPosName = d.salaryPosName
							formdata.instName = d.salaryPosInstName
							formdata.parentInstName = d.parentInstName
							_that.getParentUser(d.salaryPosId)
							uni.removeStorage({
								key:_that.userCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
								changeEditor("title2","userId",{
									link:'../../public/pageSearch/pageSearch',
									"linkParam":{
										other:JSON.stringify({
											initEmptyFlag:false
										}),
										url:"temployee/getStaffCombogrid",
										namefield:"userPosInstName",
										searchfield:'q',
										initload:true,
										cachename:_that.userCacheKey
									}
								},null,_that.autoformdata)
								_that.getYearMonth()
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
